﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace canyinguanlixitong
{
    public partial class controlForm : Form
    {
        public controlForm()
        {
            InitializeComponent();
        }
        public string stuo;
        DataSet ds = new DataSet("feiyong");
        DataSet dd = new DataSet("cho");
        string strconn = "Data Source=.;Initial Catalog=Supermarket management system;Integrated Security=True";
        private void Form1_Load(object sender, EventArgs e)
        {
            search();
            dzh();
            search2();
            search3();
        }
        //表2
        public void search3()
        {
            DataSet sd = new DataSet("biao2");
            SqlConnection conn = new SqlConnection(strconn);
            conn.Open();
            string sql = "select fydate,fyName,fymoney,fyman from dbo.fybiao";
            SqlDataAdapter a = new SqlDataAdapter(sql, conn);
            a.Fill(sd, "biao2");
            dataGridView2.DataSource = sd.Tables["biao2"];
        }
        //
        public void search2()
        {
            DataSet dl = new DataSet("do");
            SqlConnection conn = new SqlConnection(strconn);
            conn.Open();
            string sql = "select fymoney,fyName from dbo.fybiao";
            SqlDataAdapter a = new SqlDataAdapter(sql, conn);
            a.Fill(dl, "do");
            dataGridView1.DataSource = dl.Tables["do"];
        }
        public void dzh()
        {

            SqlConnection conn = new SqlConnection(strconn);
            if (this.dgvrr.SelectedCells.Count > 0)
            {

                if (dd.Tables["cho"] != null)
                {
                    dd.Tables["cho"].Clear();
                }
                string sql = "select fyName,fymoney,fytype,fydate,fyman from dbo.fybiao where fyName='" + stuo + "'";
                SqlDataAdapter a = new SqlDataAdapter(sql, conn);
                a.Fill(dd, "cho");
                dgvwei.DataSource = dd.Tables["cho"];
            }
        }
        //查询
        public string good;
        public void search()
        {
            SqlConnection conn = new SqlConnection(strconn);
            if (ds.Tables["feiyong"] != null)
            {
                ds.Tables["feiyong"].Clear();
            }
            string sql = "select fyID,fyName,fymoney,fytype from dbo.fybiao ";
            SqlDataAdapter a = new SqlDataAdapter(sql, conn);
            a.Fill(ds, "feiyong");
            dgvrr.DataSource = ds.Tables["feiyong"];
           
            

        }
        private void tab1_Click(object sender, EventArgs e)
        {

        }

        private void tabPage5_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox3_Click(object sender, EventArgs e)
        {

        }

        private void tsbaddmoney_Click(object sender, EventArgs e)
        {
            frmaddmoney fm = new frmaddmoney();
            fm.Show();
        }

        private void tsbwowo_Click(object sender, EventArgs e)
        {
            frmaddget fg = new frmaddget();
            fg.Show();
        }

        private void 增加费用ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmaddmoney fm = new frmaddmoney();
            fm.Show();
        }

        private void 增加收入ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmaddget fg = new frmaddget();
            fg.Show();
        }

        private void dgvrr_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void dgvwei_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            this.Close();
        }

        private void tsbbreak_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        DataSet dl = new DataSet("wow");
        private void dgvrr_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection(strconn);
            conn.Open();
            //if (dl.Tables["wow"]!=null)
            //{
            //    dl.Tables["wow"].Clear();
            //}
            good = Convert.ToString(this.dgvrr.SelectedRows[0].Cells["Co1"].Value);
            string sql = "select fyName,fymoney,fydate,fyman from dbo.fybiao where fyName='" + good + "'";
            SqlDataAdapter dap = new SqlDataAdapter(sql, conn);
            dap.Fill(dl, "wow");
            dgvwei.DataSource = dl.Tables["wow"];
        }

        private void 修改ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmupdatexm fud = new frmupdatexm();
            fud.name = this.dgvrr.SelectedRows[0].Cells["Co1"].Value.ToString();
            fud.Show();

        }

        private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection(strconn);
            if (ds.Tables["feiyong"] != null)
            {
                ds.Tables["feiyong"].Clear();
            }
            string sql = "select fyName,fymoney,fytype from dbo.fybiao ";
            SqlDataAdapter a = new SqlDataAdapter(sql, conn);
            a.Fill(ds, "feiyong");
            dgvrr.DataSource = ds.Tables["feiyong"];
           

        }
    }
}